package com.zr.entity;

import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;

/**
 * 封装返回结果
 */
public class Result<T> implements Serializable{
    private boolean success = false;//执行结果，true为执行成功 false为执行失败
//    private String code;
    private String message;//返回结果信息
    private T data;//返回数据
//    private Result(boolean flag, String message) {
//        super();
//        this.isSuccess = flag;
//        this.message = message;
//    }
//
//    private Result(boolean flag, String message, T data) {
//        this.isSuccess = flag;
//        this.message = message;
//        this.data = data;
//    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

//    public String getCode() {
//        return code;
//    }
//
//    public void setCode(String code) {
//        this.code = code;
//    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Result<T> ok() {
        Result<T> result = new Result<>();
        result.setSuccess(true);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = ok();
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok(String message, T data) {
        Result<T> result = ok(data);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> error() {
        return new Result<>();
    }

    public static <T> Result<T> error(String message) {
        Result<T> result = error();
        result.setMessage(message);
        return result;
    }

}
